import wmi
import time

def monitor_usb_events():
    c = wmi.WMI()

    print("Monitoring USB devices... Press Ctrl+C to exit.")
    try:
        while True:
            for usb_device in c.Win32_PnPEntity():
                if usb_device.Description and "USB" in usb_device.Description:
                    print(f"USB device detected: {usb_device.Description}")
            time.sleep(10)  # 检查间隔设置为10秒
    except Exception as e:
        print(f"An error occurred: {e}")
    except KeyboardInterrupt:
        print("Stopped monitoring USB devices.")

if __name__ == "__main__":
    monitor_usb_events()